//
//  ZZEmoticonPageView.swift
//  web
//
//  Created by 张卓 on 2017/2/10.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit


private let pageViewCellID = "pageViewCellID"
class ZZEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        let flowLayout = UICollectionViewFlowLayout()
        //设置itemSize
        flowLayout.itemSize = CGSize(width: ZZSCREENW, height: 216 - 35)
        //设置滚动方向
        flowLayout.scrollDirection = .horizontal
        //设置间距
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        super.init(frame: frame, collectionViewLayout: flowLayout)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置视图
    private func setupUI(){
//        backgroundColor = ZZRandomColor()
        
        //设置代理
        dataSource = self
        //注册cell
        register(ZZEmotionPageViewCell.self, forCellWithReuseIdentifier: pageViewCellID)
    }
    
}

extension ZZEmoticonPageView: UICollectionViewDataSource {
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return ZZEmoticonTools.shared.allEmoticons.count
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return ZZEmoticonTools.shared.allEmoticons[section].count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pageViewCellID, for: indexPath) as! ZZEmotionPageViewCell
        
        cell.backgroundColor = ZZRandomColor()
        cell.indexPath = indexPath
        //赋值
        cell.emoticons = ZZEmoticonTools.shared.allEmoticons[indexPath.section][indexPath.item]
        return cell
    }
    
    
}




